package com.bocai.yuweiwangluo.activity;


import android.view.View;
import android.widget.LinearLayout;

import com.bocai.yuweiwangluo.R;
import com.bocai.yuweiwangluo.View.XListView;
import com.bocai.yuweiwangluo.base.BaseActivity;
import com.bocai.yuweiwangluo.presenter.MyCouponListPresenter;
import com.bocai.yuweiwangluo.viewModel.IMyCouponListView;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;

/**
 * 优惠券界面
 */
public class CouponsActivity extends BaseActivity implements View.OnClickListener,IMyCouponListView,XListView.IXListViewListener
{

    @ViewInject(R.id.lv_mygame_list)
    XListView lv_mygame_list;
    @ViewInject(R.id.ll_nocotent)
    LinearLayout llnoContent;
    @ViewInject(R.id.ll_refresh)
    LinearLayout llRefresh;
    private int page=1;
    MyCouponListPresenter myCouponListPresenter;
    @Override
    protected int contentView() {
        return R.layout.activity_coupons;
    }

    @Override
    protected void setData() {
        ViewUtils.inject(this);
        initToolbar("优惠券");
        initEvent();
        getMyCouponListPresenter();
        getData();
    }

    private void getData() {
        myCouponListPresenter.getMyConponList();
    }

    @Override
    protected void initEvent() {
        super.initEvent();
        llRefresh.setOnClickListener(this);
        lv_mygame_list.setPullLoadEnable(true);
        lv_mygame_list.setPullRefreshEnable(true);
        lv_mygame_list.setXListViewListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.ll_refresh:
                llRefresh.setVisibility(View.GONE);
                onRefresh();
                break;
        }

    }

    @Override
    public MyCouponListPresenter getMyCouponListPresenter() {
        myCouponListPresenter=new MyCouponListPresenter(this,this,this);
        return myCouponListPresenter;
    }

    @Override
    public LinearLayout getllRefresh() {
        return llRefresh;
    }

    @Override
    public int getmyPage() {
        return page;
    }

    @Override
    public void onLoad() {
        lv_mygame_list.stopRefresh();
        lv_mygame_list.stopLoadMore();
        lv_mygame_list.setRefreshTime("");
    }

    @Override
    public XListView getListView() {
        return lv_mygame_list;
    }

    @Override
    public LinearLayout getnoContent() {
        return llnoContent;
    }



    @Override
    public void finishActivity() {
        this.finish();
    }

    @Override
    public void onRefresh() {
        page=1;
        lv_mygame_list.setPullLoadEnable(true);
        myCouponListPresenter.getMyConponList();
    }

    @Override
    public void onLoadMore() {
        page++;
        myCouponListPresenter.getMyConponList();
    }
}
